﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;

namespace YJKRevitKernel.ElementSearchUtility.LinkDocumentSuite
{
	public class BaseLinkDocumentResultBean
	{
		public Element UseElement
		{
			get
			{
				return this.m_useElement;
			}
			private set
			{
				this.m_useElement = value;
			}
		}

		public RevitLinkInstance UseLinkeInstance
		{
			get
			{
				return this.m_useLinkeInstance;
			}
			private set
			{
				this.m_useLinkeInstance = value;
			}
		}

		public int ElementId
		{
			get
			{
				return this.m_nElementId;
			}
			private set
			{
				this.m_nElementId = value;
			}
		}

		public int LinkeInstanceId
		{
			get
			{
				return this.m_nLinkeInstanceId;
			}
			private set
			{
				this.m_nLinkeInstanceId = value;
			}
		}

		public List<RevitLinkInstance> LstParentRevitLinkInstance
		{
			get
			{
				return this.m_lstParentRevitLinkInstance;
			}
			private set
			{
				this.m_lstParentRevitLinkInstance = value;
			}
		}

		public BaseLinkDocumentResultBean(Element input, RevitLinkInstance inputLink = null, List<RevitLinkInstance> lstParentLinkInstance = null)
		{
			this.ElementId = -1;
			this.LinkeInstanceId = -1;
			this.UseElement = input;
			this.UseLinkeInstance = inputLink;
			if (this.UseElement != null)
			{
				this.ElementId = this.UseElement.Id.IntegerValue;
			}
			if (this.UseLinkeInstance != null)
			{
				this.LinkeInstanceId = this.UseLinkeInstance.Id.IntegerValue;
			}
			if (lstParentLinkInstance == null)
			{
				lstParentLinkInstance = new List<RevitLinkInstance>();
				return;
			}
			this.LstParentRevitLinkInstance = lstParentLinkInstance;
		}

		public Transform GetTotalTransform()
		{
			Transform transform = Transform.Identity;
			if (this.UseLinkeInstance != null)
			{
				transform = this.UseLinkeInstance.GetTotalTransform();
			}
			foreach (RevitLinkInstance revitLinkInstance in this.LstParentRevitLinkInstance)
			{
				if (transform == null)
				{
					transform = revitLinkInstance.GetTotalTransform();
				}
				else
				{
					transform = transform.Multiply(revitLinkInstance.GetTotalTransform());
				}
			}
			return transform;
		}

		public override bool Equals(object obj)
		{
			if (!(obj is BaseLinkDocumentResultBean))
			{
				return false;
			}
			BaseLinkDocumentResultBean baseLinkDocumentResultBean = obj as BaseLinkDocumentResultBean;
			return baseLinkDocumentResultBean.ElementId == this.ElementId && baseLinkDocumentResultBean.LinkeInstanceId == this.LinkeInstanceId;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		private Element m_useElement;

		private RevitLinkInstance m_useLinkeInstance;

		private int m_nElementId;

		private int m_nLinkeInstanceId;

		private List<RevitLinkInstance> m_lstParentRevitLinkInstance = new List<RevitLinkInstance>();
	}
}
